var e, o = (e = require("../../miniprogram_npm/@vant/weapp/toast/toast")) && e.__esModule ? e : {
    default: e
};

var t = require("../../utils/config");

Page({
    data: {
        text: "等待支付……",
        options: {
            payParam: "",
            orderno: "",
            token: "",
            backUrl: "",
            desc: "",
            systemid: ""
        },
        show: !1,
        payImgUrl: "".concat(t.resourceRoot, "paying.gif")
    },
    onLoad: function(e) {
        this.showPopup(), console.log(e), this.setData({
            options: e
        }), this.requestPayment();
    },
    requestPayment: function() {
        var e = this, o = this, n = this.data.options, a = JSON.parse(decodeURIComponent(n.payParam));
        console.log(11, n), console.log(22, a), wx.requestPayment({
            appId: a.appId,
            timeStamp: a.timeStamp,
            nonceStr: a.nonceStr,
            package: a.package,
            signType: a.signType,
            paySign: a.paySign,
            success: function(a) {
                var s = e.data.options.systemid, i = e.data.options.orderno;
                console.log("支付成功", "SystemId:", s, "OrderNo:", i);
                console.log("resData:", JSON.stringify(a));
                var c = "".concat(t.h5PaySuccessUrl, "?orderno=").concat(e.data.options.orderno, "&msg=").concat("ok", "&wtoken=").concat(e.data.options.token, "&systemid=").concat(e.data.options.systemid);
                console.log(c);
                var r = encodeURIComponent(c);
                if (console.log(r), console.log("付款成功"), o.setData({
                    show: !1
                }), e.data.options.systemid == t.selfSelectedOrderSystemId) {
                    var l = n.backUrl, d = decodeURIComponent(l).split("?")[1].split("&"), p = "";
                    d.forEach(function(e) {
                        var o = e.split("=");
                        "backUrl" == o[0] && (p = o[1]);
                    }), "" != p && wx.reLaunch({
                        url: "/pages/webview/webview?h5=".concat(p)
                    });
                } else s == t.filmPrintOrderSystemId ? (console.log("胶片打印支付页面跳转", e.data), wx.reLaunch({
                    url: "/pages/film-print-invoice/film-print-invoice?orderNo=".concat(i)
                })) : wx.reLaunch({
                    url: "/pages/webview/webview?h5=".concat(r)
                });
            },
            fail: function(a) {
                console.log("支付失败:", a);
                a.errMsg.indexOf("fail cancel"), console.log(JSON.stringify(a));
                var s = n.backUrl;
                console.log(s), o.setData({
                    show: !1
                }), e.data.options.systemid == t.selfSelectedOrderSystemId ? wx.switchTab({
                    url: "/pages/index/index"
                }) : e.data.options.systemid == t.filmPrintOrderSystemId ? (console.log("胶片打印支付失败"), 
                wx.reLaunch({
                    url: "/pages/my-link-report/my-link-report"
                })) : wx.reLaunch({
                    url: "/pages/webview/webview?h5=".concat(s)
                });
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    onGoBack: function() {
        console.log(getCurrentPages()), wx.navigateBack({
            delta: 1
        });
    },
    showWait: function() {
        var e = 5, t = o.default.loading({
            duration: 0,
            forbidClick: !0,
            message: "请稍候".concat(e, " 秒"),
            loadingType: "spinner",
            selector: "#custom-selector"
        }), n = setInterval(function() {
            --e ? t.setData({
                message: "请稍候 ".concat(e, " 秒")
            }) : (clearInterval(n), o.default.clear());
        }, 1e3);
    },
    showPopup: function() {
        o.default.loading({
            mask: !0,
            message: "请稍后...",
            duration: "toast",
            selector: "#custom-selector",
            loadingType: "spinner"
        });
    }
});